package main

import (
	"fmt"
	"io"
	"net/http"
)

func main() {
	// 设置路由

	http.HandleFunc("/user", func(writer http.ResponseWriter, request *http.Request) {
		// 通过writer 将数据返回客户端
		// request包含客户发来的数据
		fmt.Println("request:", request)
		_, _ = io.WriteString(writer, `{"name":"zhangsan"}`)
	})
	http.HandleFunc("/name", func(writer http.ResponseWriter, request *http.Request) {
		fmt.Println("request:", request)
		_, _ = io.WriteString(writer, `testName`)
	})
	http.HandleFunc("/address", func(writer http.ResponseWriter, request *http.Request) {
		fmt.Println("request:", request)
		_, _ = io.WriteString(writer, `{"address":"广州"}`)
	})
	// 设置监听
	fmt.Println("Http Server start...")
	if err := http.ListenAndServe("localhost:8089", nil); err != nil {
		fmt.Println("http start failed,err:", err)
		return
	}

}
